package com.xb.loan.cashier.biz.service.impl;

import com.xb.loan.cashier.biz.dao.CashierPayChannelTypeDao;
import com.xb.loan.cashier.biz.dao.bean.CashierPayChannelType;
import com.xb.loan.cashier.biz.service.CacheService;
import com.xb.loan.cashier.biz.service.CashierPayChannelTypeService;
import com.xb.loan.cashier.biz.service.cache.RedisMethodCacheSupport;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("cashierPayChannelTypeService")
public class CashierPayChannelTypeServiceImpl implements CashierPayChannelTypeService, CacheService {

    @Autowired
    private CashierPayChannelTypeDao cashierPayChannelTypeDao;
    
    @Override
    public CashierPayChannelType getByPaychannelType(int payChannelType) {
        CashierPayChannelType type = RedisMethodCacheSupport.getBean(CashierPayChannelType.class, payChannelType+"");
        if(type!=null){
            return type;
        }
        type = cashierPayChannelTypeDao.getByPaychannelType(payChannelType);
        if(type==null){
            return null;
        }
        RedisMethodCacheSupport.setBean(CashierPayChannelType.class, type, payChannelType+"");
        return type;
    }

    @Override
    public void insert(CashierPayChannelType cashierPayChannelType) {
        cashierPayChannelTypeDao.insertSelective(cashierPayChannelType);
    }

    @Override
    public void clearCache(String methodName) {
        RedisMethodCacheSupport.clear(methodName);
    }

    @Override
    public void clearCacheAll() {
        RedisMethodCacheSupport.clearAll();
    }

	@Override
	public List<Map<String, Object>> queryPayChannelTypeByPage(int pageNum,
                                                               int pageSize) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("pageNum", pageNum);
		params.put("pageSize", pageSize);
		return cashierPayChannelTypeDao.queryPayChannelTypeByPage(params);
	}

	@Override
	public int queryPayChannelTypeCount() {
		return cashierPayChannelTypeDao.queryPayChannelTypeCount();
	}

	@Override
	public List<CashierPayChannelType> queryPayChannelTypeListAll() {
		return cashierPayChannelTypeDao.selectAll();
	}
}
